package com.gupaoedu.vip.proxy.cglib;

import com.gupaoedu.vip.proxy.jdk.Person;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by zhaozhonghai on 2017/5/22.
 */
public class LianJia implements MethodInterceptor{

    public Object getInstance(Class target){
        Enhancer enhancer=new Enhancer();
        enhancer.setSuperclass(target);
        enhancer.setCallback(this);
        return enhancer.create();
    }
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
//        System.out.println("用户的名字"+this.target.getName());
//        System.out.println("用户的要求"+this.target.getSize()+this.target.getPrice());
        System.out.println("开始帮用户找房子,找到房子，联系客户看房子");
        System.out.println("----------------------");
//        method.invoke(this.target,args);
//        method.invoke(o,objects);
//        System.out.println(o.getClass());
//        System.out.println(method.getName());
//        System.out.println(methodProxy.getClass()+"==="+methodProxy.getSuperName());
        methodProxy.invokeSuper(o,objects);
        System.out.println("----------------------");
        System.out.println("客户满意，收佣金，结束");
        return null;
    }
}
